package com.xlf.book.servlet;

import com.xlf.book.biz.BookInfoBiz;
import com.xlf.book.biz.impl.BookInfoBizImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author xie'lin'feng
 * @date 2020-07-20-16:53
 * @description 删除处理器
 */
@WebServlet("/delete")
public class DoDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        BookInfoBiz bib = new BookInfoBizImpl();
        boolean result = bib.deleteInfo(Integer.valueOf(req.getParameter("id")));
        if (result){
            resp.sendRedirect("getAll");
        }else {
            PrintWriter out = resp.getWriter();
            out.print("<script>alert('删除失败!');location.href='getAll';</script>");
            out.flush();
            out.close();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
